// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
#pragma hdrstop 

#include "stdafx.h"
#include <windows.h>
#include "utils.h"


CComBSTR NLM_CONNECTIVITY_ToString(NLM_CONNECTIVITY nlmConnectivity)
{
	CComBSTR szConnectivity = "";
	if (nlmConnectivity == NLM_CONNECTIVITY_DISCONNECTED)
	{
		szConnectivity = L"network disconnected";
		return szConnectivity;
	}

	if (nlmConnectivity & NLM_CONNECTIVITY_IPV4_NOTRAFFIC)
	{
		if (szConnectivity.Length() != 0)
		{
			szConnectivity += " | ";
		}
		szConnectivity += L"network no traffic";
	}

	if (nlmConnectivity & NLM_CONNECTIVITY_IPV4_LOCALNETWORK)
	{
		if (szConnectivity.Length() != 0)
		{
			szConnectivity += " | ";
		}
		szConnectivity += L"IPv4 local connectivity";
	}

	if (nlmConnectivity & NLM_CONNECTIVITY_IPV4_INTERNET)
	{
		if (szConnectivity.Length() != 0)
		{
			szConnectivity += " | ";
		}
		szConnectivity += L"IPv4 internet connectivity";
	}

	if (nlmConnectivity & NLM_CONNECTIVITY_IPV6_LOCALNETWORK)
	{
		if (szConnectivity.Length() != 0)
		{
			szConnectivity += " | ";
		}
		szConnectivity += L"IPv6 local connectivity";
	}

	if (nlmConnectivity & NLM_CONNECTIVITY_IPV6_INTERNET)
	{
		if (szConnectivity.Length() != 0)
		{
			szConnectivity += " | ";
		}
		szConnectivity += L"IPv6 internet connectivity";
	}

	return szConnectivity;
}

CComBSTR GetSzGuid(GUID gdGuid)
{
	LPOLESTR szClsId;
	HRESULT hr = StringFromIID(gdGuid, &szClsId);
	if (FAILED(hr))
	{
		return L"{failed}";
	}
	CComBSTR bstrClsId = szClsId;
	CoTaskMemFree(szClsId);

	return bstrClsId;
}

CComBSTR NLM_NETWORK_PROPERTY_CHANGE_ToString(NLM_NETWORK_PROPERTY_CHANGE nlmNetworkPropertyChange)
{	
	CComBSTR szNetworkPropertyChange = "";

	if (nlmNetworkPropertyChange == NLM_NETWORK_PROPERTY_CHANGE_CONNECTION)
	{
		szNetworkPropertyChange += L"NLM_NETWORK_PROPERTY_CHANGE_CONNECTION";
	}

	if (nlmNetworkPropertyChange == NLM_NETWORK_PROPERTY_CHANGE_DESCRIPTION)
	{
		if (szNetworkPropertyChange.Length() != 0)
		{
			szNetworkPropertyChange += " | ";
		}
		szNetworkPropertyChange += L"NLM_NETWORK_PROPERTY_CHANGE_DESCRIPTION";
	}

	if (nlmNetworkPropertyChange == NLM_NETWORK_PROPERTY_CHANGE_NAME)
	{
		if (szNetworkPropertyChange.Length() != 0)
		{
			szNetworkPropertyChange += " | ";
		}
		szNetworkPropertyChange += L"NLM_NETWORK_PROPERTY_CHANGE_NAME";
	}

	if (nlmNetworkPropertyChange == NLM_NETWORK_PROPERTY_CHANGE_CATEGORY_VALUE)
	{
		if (szNetworkPropertyChange.Length() != 0)
		{
			szNetworkPropertyChange += " | ";
		}
		szNetworkPropertyChange += L"NLM_NETWORK_PROPERTY_CHANGE_CATEGORY_VALUE";
	}

	return szNetworkPropertyChange;
}

CComBSTR NLM_CONNECTION_PROPERTY_CHANGE_ToString(NLM_CONNECTION_PROPERTY_CHANGE nlmConnectionPropertyChange)
{
	CComBSTR szConnectionPropertyChange = "";

	if (nlmConnectionPropertyChange == NLM_CONNECTION_PROPERTY_CHANGE_AUTHENTICATION)
	{
		szConnectionPropertyChange += L"NLM_CONNECTION_PROPERTY_CHANGE_AUTHENTICATION";
	}

	return szConnectionPropertyChange;
}
